*****************************************************
****** Tiffany Barnes and Mirya Holman **************
****** After the JD panel analysis ******************
****** Start with he folder structure outlined in the readme file ****
****** with three folders (data, code, results) *****
****** Download the full After the JD data from https://www.icpsr.umich.edu/web/ICPSR/series/1560 ****
****** place the data in the data folder ******
****** and set your working directory below in the "Base" to where you have your folders *****



clear
set more off 

set scheme tab1
graph set window fontface default

global Base "SET TO YOUR BASE FOLDER"
global Dofiles "$Base\code"
global Data "$Base\data"
global Results "$Base\results"

global tt1 cells(b(star fmt(%-9.3f)) se(fmt(%-9.3f) par( [ ] )) blank) stats (r2 N, fmt(%9.2f %9.0g)) style(fixed) starlevel("*" 0.10 "**" 0.05 "***" 0.01)

cd "$Dofiles"

**** turn on if you want to clean data **** 

*do "ajd_cleaning.do"

***** turn on if you want to merge datasets together **** 

*do "ajd_merging.do"

clear 

use "$Data\ajd_panel.dta"

cd "$Results"

**** labeling **** 

foreach var of varlist whitew1 whitew2	whitew3 {
label var `var' "White" 
}

foreach var of varlist agew1 agew2	agew3 {
label var `var' "Age" 
}

**** generating some change variables **** 

gen change_agenticw12 = agentic_goals_scalew2 - agentic_career_scalew1
gen change_agenticw23 = agentic_goals_scalew3 - agentic_goals_scalew2


label var ag_influencial_person_scale "Be influencial person"
label var ag_intellectual_challenge_scale "Intellectual challenge"
label var ag_wealth_scale "Accumulate wealth"
label var change_agenticw12 "Change in agentic goals, Wave 1 to 2"
label var change_agenticw23 "Change in agentic goals, Wave 2 to 3"
label var agentic_goals_scalew2 "Agentic scale, Wave 2"
label var agentic_goals2_scale "Agentic scale, Wave 3"

**** setting global controls ***** 

global controlsw1 genderw1 whitew1 
global controlsw2 agew2 marriedw2 any_childrenw2 law_rankw2
global controlsw3 agew3 marriedw3 any_childrenw3 law_rankw3
global controlsw1_2 whitew1
global controlsw3_2 fem_expertisew3 courtw3 



**** first, summarize agentic goals **** 

graph hbox  ag_intellectual_challenge_scale ag_wealth_scale ag_influencial_person_scale agentic_goals_scalew2 agentic_goals2_scale,  box(3,color(forest_green)) box(3,color(%60)) box(4,color(orange_red)) box(4,color(%40)) asyvars showyvars leg(off) 
	graph save Graph "agentic_boxplotw2.gph", replace
	graph export agentic_boxplotw2.png, replace width(1200)
	
	
	
**** agentic goals by gender **** 

label define genderw1 0 "Women" 1 "Men"
lab val genderw1 genderw1
	
stripplot agentic_goals2_scale, by(genderw1, compact note("")  row(1)) ///
jitter(4) box  iqr center stack h(0.5) ///
ytitle("Agentic Goals") mcolor(green)  ///
vertical plotregion(lcolor(black) color(white))  name(agentic_gender, replace) 
	graph export agentic_by_gender.png, replace width(1200)

	
	**** do agentic and communal goals persist across time? **** 


	twoway scatter agentic_goals_scalew2 agentic_goals2_scale if genderw1 == 0 , msymbol(t) msize(small) jitter(4) ///
	|| scatter agentic_goals_scalew2 agentic_goals2_scale if genderw1 == 1, msymbol(Oh) msize(small) jitter(4)  ///
	|| lfit agentic_goals_scalew2 agentic_goals2_scale if genderw1 == 0,  lcolor(dkgreen) lpattern(dash) ///
    || lfit agentic_goals_scalew2 agentic_goals2_scale if genderw1 == 1, ///
	ytitle("Agentic goals (Wave 2)") xtitle("Agentic goals (Wave 3)") ///
	title("") 	///
	plotregion(lcolor(black) color(white))  ///
	legend(order(1 "Women" 2 "Men" 3 "Women slope" 4 "Men slope") rows(1) pos(6))
	graph save Graph "agentic_goals.gph", replace	
	graph export goals_across_waves.png, replace width(1800)

		

label define political_goals 1 "Not important at all" 5 "Very important"
lab val political_goals political_goals
	
	stripplot agentic_goals2_scale, by(political_goals , compact note("")  row(1)) ///
	jitter(4) box  iqr center stack h(0.5) ///
	ytitle("Agentic goals (Wave 3)") mcolor(green) ///
	xtitle(Becoming a Politician (Wave 3)) ///
	vertical plotregion(lcolor(black) color(white))  name(G1, replace) 
	graph save political_agentic.gph, replace
	graph export "political_agentic.png", replace width(1800)
	
	
**** does agenticism influence ambition? **** 

eststo clear 

	eststo wave2: reg political_goalsw3 agentic_goals_scalew2 $controlsw1 $controlsw2  [pw=CWT_NAT_NR]
	margins, at(agentic_goals_scalew2=(.40(.15)1)) atmeans
	eststo wave3: reg political_goalsw3 agentic_goals2_scale $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
	margins, at(agentic_goals2_scale=(.25(.15).85)) atmeans	
			# delimit ;
		esttab 
		using agentic_ambition.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("agentic goals and ambition")
			 label nonumbers
			addnote("Controls include age, white, married, any children. Survey weights applied.")
			compress replace;
		#delimit cr
		


			
**** gender wave 1 agentic wave 2 ambition wave 3 **** 
eststo clear 

reg political_goalsw3 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
eststo political
reg agentic_goals_scalew2 $controlsw1 $controlsw2  [pw=CWT_NAT_NR]
eststo gender_agentic
reg agentic_goals2_scale $controlsw1 $controlsw2  [pw=CWT_NAT_NR]
eststo gender_agenticw3

	# delimit ;
		esttab 
		using mediation_table2.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("Gender predicts agentic goals, ambition")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr

		eststo clear 
		
reg political_goalsw3 agentic_goals_scalew2 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
eststo political_agentic
reg political_goalsw3 agentic_goals2_scale $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
eststo political_agenticw3
reg political_goalsw3 c.agentic_goals_scalew2##i.genderw1 $controlsw1_2 $controlsw3  [pw=CWT_NAT_NR]
eststo political_agentic_gender
reg political_goalsw3 c.agentic_goals2_scale##i.genderw1 $controlsw1_2 $controlsw3  [pw=CWT_NAT_NR]
eststo political_agentic_genderw3

		# delimit ;
		esttab 
		using mediation_table3.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("Gender predicts agentic goals, ambition")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr
		
**** figure of gender x agentic *** 

reg political_goalsw3 c.agentic_goals_scalew2##i.genderw1 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	margins genderw1, at(agentic_goals_scalew2=(0(.1)1))
	
	marginsplot, title("") ///
	legend (rows(1) pos(6)) ///
    xtitle ("Agentic Goals (Wave 2)", size(large)) ///
    ytitle ("Ambition (Wave 3)", size(large))  ///
    recast(line) recastci(rarea) ///
	 ci1opts(color(gold%40)) ///
	 ci2opts(color(green%30)) ///
    legend(rows(1)) ///
    plot(, label ("Women" "Men")) ///
    plot1opts(lpattern(".") lcolor(gold) lwidth(thick))  /// 
    plot2opts(lpattern("--") lwidth(thick)) /// dashed line for plot 2
    legend(size(large))
	graph save "interaction.gph", replace
	graph export "interaction.jpg", replace
	
	reg political_goalsw3 c.agentic_goals2_scale##i.genderw1 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	margins genderw1, at(agentic_goals2_scale=(0(.1)1))
	
	marginsplot, title("") ///
	legend (rows(1) pos(6)) ///
	xtitle ("Agentic Goals (Wave 3)", size(large)) ///
	ytitle ("Ambition (Wave 3)", size(large))  ///
    recast(line) recastci(rarea) ///
	 ci1opts(color(gold%40)) ///
	 ci2opts(color(green%30)) ///
    legend(rows(1)) ///
    plot(, label ("Women" "Men")) ///
    plot1opts(lpattern(".") lcolor(gold) lwidth(thick))  /// 
    plot2opts(lpattern("--") lwidth(thick)) /// dashed line for plot 2
    legend(size(large))
	graph save "interactionw3.gph", replace
	graph export "interactionw3.jpg", replace
	
	grc1leg interaction.gph  interactionw3.gph, ycommon ///
	col(2) graphregion(margin(none)) ysize(3.5) 
	graph save interaction_combined.gph, replace
	graph export interaction_combined.png, replace width(1800)
	
eststo clear 
	
 reg political_goalsw3 agentic_satisfaction_scalew2 agentic_goals_scalew2 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
	margins, at(agentic_satisfaction_scalew2=(0(.1)1))    atmeans post 
	estimates store satisfaction
	
 reg political_goalsw3 agentic_satisfaction_scalew2 agentic_goals_scalew2 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
	margins, at(agentic_goals_scalew2=(0(.1)1))   atmeans post 
	estimates store goals
	

coefplot (satisfaction, label(Agentic Satisfaction)) (goals, label (Agentic Goals)), ///
	ytitle("Effect on Political Ambition") ///
	xlab(, labsize(medium)) xtitle ("Agentic Satisfaction / Goals") ///
	at recast(line) lwidth(*2) ciopts(recast(rline) lc(gray) lp(-) lw(vthin)) ///
	legend(size(medium)) 
	graph save satisfaction_goals_line.gph, replace
	graph export satisfaction_goals_line.jpg, replace width(1800)


	eststo clear 
	
	reg political_goalsw3 c.agentic_satisfaction_scalew3##i.genderw1 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	margins genderw1, at(agentic_satisfaction_scalew3=(0(.1)1))
	
	marginsplot, title("") ///
	legend (rows(1) pos(6)) ///
	xtitle ("Agentic Satisfaction (Wave 3)", size(large)) ///
	ytitle ("Ambition (Wave 3)", size(large))  ///
	recast(line) recastci(rarea) ciopt(color(%40)) ///
	legend(rows(1)) ///
	plot(, label ("Women" "Men")) ///
	plot1opts(lpattern(".")) plot2opts(lpattern("--")) ///
	legend(size(large))
	graph save "interaction_satisfactionw3.gph", replace
	graph export "interaction_satisfactionw3.jpg", replace
	
	
	reg political_goalsw3 agentic_satisfaction_scalew2 genderw1 agentic_goals_scalew2 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	eststo wave2
	reg political_goalsw3 agentic_satisfaction_scalew3 genderw1 agentic_goals_scalew2 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	eststo wave3
	reg political_goalsw3 c.agentic_satisfaction_scalew3##i.genderw1 agentic_goals_scalew2 $controlsw1_2 $controlsw3   [pw=CWT_NAT_NR]
	eststo interaction
	
			# delimit ;
		esttab 
		using satisfaction.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("Gender predicts agentic goals, ambition")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr
	
		
 reg political_goalsw3 agentic_satisfaction_scalew2##i.genderw1 agentic_goals_scalew2 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
	margins genderw1, at(agentic_goals_scalew2=(0(.1)1))
	estimates store goals
	
	eststo clear 
	
eststo agentic_satisfaction1: reg political_goalsw3 agentic_satisfaction_scalew2 agentic_goals_scalew2 $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
eststo agentic_satisfaction2: reg political_goalsw3 agentic_satisfaction_scalew3 agentic_goals2_scale $controlsw1 $controlsw3  [pw=CWT_NAT_NR]
			# delimit ;
		esttab 
		using satisfaction_ambition.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("agentic satisfication and ambition")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr




**** looking at change over time *** 

eststo clear 

reg change_agenticw23 agentic_goals_scalew2 $controlsw1 $controlsw2 $controlsw3_2 [pw=CWT_NAT_NR]
eststo gender_agentic
reg political_goalsw3 change_agenticw23 agentic_goals_scalew2 $controlsw1 $controlsw3 $controlsw3_2 [pw=CWT_NAT_NR]
eststo political_agentic
reg political_goalsw3 c.change_agenticw23##i.genderw1 c.agentic_goals_scalew2##i.genderw1 $controlsw1_2 $controlsw3 $controlsw3_2 [pw=CWT_NAT_NR]
eststo political_agentic_interact

		# delimit ;
		esttab 
		using change_agentic.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("Gender predicts agentic goals, ambition")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr

				 

**** individual measures of agenticism **** 


eststo clear 

eststo comp1: reg political_goalsw3 ag_influencial_person_scale  [pw=CWT_NAT_NR]
eststo comp2: reg political_goalsw3  ag_intellectual_challenge_scale [pw=CWT_NAT_NR]
eststo comp3: reg political_goalsw3   ag_wealth_scale  [pw=CWT_NAT_NR]

		# delimit ;
		esttab 
		using ambition_components.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("individual agentic goals and ambition")
			 label nonumbers
			addnote("Controls include age, white, married, any children. Survey weights applied.")
			compress replace;
		#delimit cr
	

eststo clear 

reg political_goalsw3 $controlsw1 $controlsw2
eststo gender_agentic
reg political_goalsw3 agentic_goals_scalew2 $controlsw1 $controlsw3 
eststo political_agentic
reg political_goalsw3 c.agentic_goals_scalew2##i.genderw1 $controlsw1_2 $controlsw3 
eststo political_agentic_gender

		# delimit ;
		esttab 
		using mediation_waves.rtf, nogap se b(%9.2f) starlevels(* .05) r2(%9.3f) 
			title("Gendered relationship between goals in W2 and Ambition in W3")
			 label nonumbers
			addnote("Controls include age, white, law school rank, married, any children")
			compress replace;
		#delimit cr
		

		